let timer: any = null;

/**
 * 防抖
 * @param callback 回调
 * @param delay 延迟时间
 * @returns
 * */
export const debounceHandle = (callback: Function, delay: 200 | number = 200): void => {
    clearTimeout(timer)
    timer = setTimeout(() => {
        callback();
        timer = null;
    }, delay);
}


let timers: any = null;
/**
 * 截流
 * @param callback 回调
 * @param delay 延迟时间
 * @returns
 * */
export const throttleHandle = (callback: Function, delay: 200 | number = 200): void => {
    if(timers) return;
    timers = setTimeout(() => {
        callback();
        clearTimeout(timers)
        timers = null;
    }, delay);
}